package com.le.tester.onjava8.l_2_2_2;

import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * createTime：2023/1/6 14:02
 * description：clone List，不建议使用
 */

class Int {
    private int i;

    Int(int i) {
        this.i = i;
    }

    public void increment() {
        i++;
    }

    @Override
    public String toString() {
        return Integer.toString(i);
    }
}

public class CloneArrayList {
    public static void main(String[] args) {
        ArrayList<Int> v = IntStream.range(0, 10)
                .mapToObj(Int::new)
                .collect(Collectors.toCollection(ArrayList::new));

        System.out.println("v: " + v);

        @SuppressWarnings("unchecked")
        ArrayList<Int> v2 = (ArrayList<Int>) v.clone();

        v2.forEach(Int::increment);

        System.out.println("v :" + v);

    }
}
